//index.js
//获取应用实例
const app = getApp()
var utl = require('../../utils/util.js');
Page({
  data: {
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    items:['remember'],
    ischecked:true,
    ntice:'',
    nohot:false,
    jrfwArr: [{ 'businessName': '统计', 'imagePath': '/pages/images/icon_skgc.png' }, { 'businessName': '付款', 'imagePath': '/pages/images/icon_sk.png' }, { 'businessName': '余额查询', 'imagePath': '/pages/images/icon_jymx.png' }, { 'businessName': '卡管理', 'imagePath': '/pages/images/icon_sz.png' }]
  },
 
  onLoad: function (e) {
    console.log(e.oderlist);
    var od = e.oderlist;
    if(od){
      var order = JSON.parse(od);
      if (order) {
        app.globalData.payord = od;
        var money = order.money;
        wx.showModal({
          title: '提示',
          content: '您有一笔付款订单需要支付，是否去支付',
          success(res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '/pages/orderlist/orderdetail?order=' + od,
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })
      }
    }
    

    wx.login({
      success(res) {
        if (res.code) {
          //发起网络请求
          // wx.request({
          //   url: 'https://test.com/onLogin',
          //   data: {
          //     code: res.code
          //   }
          // })
          utl.httServer('USER_LOGIN_WX', { 'PARENT_ID': '', 'CODE': res.code, 'APPID': 'wx8a9db7a7d03bb6a7', 'SECRET':'ad543c4e2529ebe4a75a499b65a21b8d'}, (err, res) => {
            if (res.STATUS == '-1'){
              wx.showToast({
                title: '您的账户不可用，请联系客服',
                icon: 'none',
                duration: 2000
              })
              return;
            }
            if (res.PHONE == undefined || res.PHONE == ''){
              wx.redirectTo({
                url: '/pages/login/index',
              })
            }else{

            }  
            app.globalData.sessonid = res.SESSION_ID;
            app.globalData.userid = res.USER_ID;
            app.globalData.telphone = res.PHONE;
            app.globalData.loginresult = res;
          })
          console.log(res.code);
        } else {
          wx.showToast({
            title:res.errMsg,
            icon:'none',
            duration:2000
          })
          console.log('登录失败！' + res.errMsg)
        }
      }
    })
    console.log(e);
    var loginend = e.section;
    if (loginend){
      this.queryTop();
      // this.queryNotice();
    }else{
     
    }
  },
  //账单查询
  orderAction:function(){
    
    wx.navigateTo({
      url: '/pages/orderlist/index',
    })

  },
  //收款
  gopayAction:function(){
      wx.navigateTo({
        url: '/pages/checkm/index',
      })
  },
  //查询消息
  queryNotice:function(){
    wx.showLoading({
      title: '请求中...',
    })
    utl.serverToken('/epay_apps/push/getPushMsgList', { 'pageNum': 1, 'pageSize': 1, "msgRemark": 1 }, (err, res) => {
      wx.hideLoading();
      var notice = res.response.recordList;
      if(notice.length==1){
        var tish = notice[0].content;
        this.setData({
          ntice:tish,
        })
      }
    })
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  radioChange:function(e){
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    var ischeck = this.data.ischecked;
    ischeck = !ischeck;
    this.setData({
      ischecked:ischeck
    })
  },
  jumdetail:function(e){
    const dex = e.currentTarget.dataset.info;
    var arr = this.data.jrfwArr;
    var gerp = arr[dex];
    var name = gerp.businessName;
    switch(dex){
      case 0:
    {
      wx.navigateTo({
        url: '/pages/service/statistics',
      })
    }
      break;
      case 1:{
        wx.navigateTo({
          url: '/pages/service/paymoney',
        })
      }
      break;
      case 2:{
        wx.navigateTo({
          url: '/pages/profit/index',
        })
      }
      break;
      case 3:{
        wx.navigateTo({
          url: '/pages/skcard/mcard',

        })
      }
      break;
    }
  }
})
